/**
 * Created by oneminute on 8/29/14.
 */

var lz = require("../../lib/utils/modules")();
var amqp = require("amqp");

var connection = amqp.createConnection(lz.Config.rabbit.server);

connection.on("ready", function () {
    console.log("[client] connection is ready.");
    //connection.exchange(lz.Config.rabbit.log.exchange, {passive: true}, function (_exchange) {
    //console.log("[client] exchange " + _exchange.name + " is ready.");
    connection.queue("iwant.queue.log", {
        durable: true,
        autoDelete: false
    }, function (_queue) {
        console.log("[client] queue " + _queue.name + " is openned.");
        _queue.bind(lz.Config.rabbit.log.exchange, "iwant.#");
        _queue.on("queueBindOk", function () {
            console.log("[client] queue bind ok.");
            /*for (var i = 0; i < 100; i++) {
             lz.Logger.info("log test 中文 %d", i);
             }*/
            _queue.subscribe({}, function (_msg) {
                var buffer = new Buffer(_msg.data);
                console.log("[client] " + buffer.toString());
            });
        });
    });
    //});
});